#include "sdopencv/PHaarClassifier.hpp"

using namespace std;
using namespace sdopencv;

int PHaar_classify(struct PHaarFCParam *hfc, PolygonalIntegrator *pi, const CvPoint &topleft)
{
    int i, j;
    double val = 0;
    CvPolygon p;

    PHaarFeature *hf = hfc->hf;

    if(topleft.x != 0 || topleft.y != 0) for(i = 0; i < 2; ++i)
    {
        p.resize(hf->p[i].size());
        for(j = 0; j < p.size(); ++j)
        {
            p[j].x = hf->p[i][j].x + topleft.x;
            p[j].y = hf->p[i][j].y + topleft.y;
        }
        val += pi->integrate(p) / hf->A[i];
    }
    else
        val = pi->integrate(hf->p[0]) / hf->A[0] + pi->integrate(hf->p[1]) / hf->A[1];

    return (val >= hfc->threshold) ^ hfc->parity;
}
